class TagsController < ApplicationController
  
  before_filter :set_current_menu_and_title
  
  def index
    @tags = Tag.counts
  end

  def show
    if request.request_uri.include?('.')
      redirect_to request.request_uri[0, request.request_uri.index('.')]
      return
    end
    @tag = Tag.find_by_name(CGI.unescape(params[:id]))
    if @tag.nil?
      @tag = Tag.find(:first, :conditions => ["name LIKE ?", '%' + CGI.unescape(params[:id]) + '%'])
    end
    if @tag
      @blogs = Blog.find_tagged_with(@tag.name)
      @tutorials = Tutorial.find_tagged_with(@tag.name)
      @resources = Resource.find_tagged_with(@tag.name)
      @posts = Post.find_tagged_with(@tag.name)
    end
    @title = @tag
    @keywords = @tag
    @description = @tag
  end


  private
    def set_current_menu_and_title
      @current_menu = :tag
      @title = "标签"
    end
end
